<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        #div1{
            width: 200px;
            height: 200px;
            background: red;
            opacity: 0.3;
            filter: alpha(opacity:30);
        }
    </style>
</head>
<body>
  <div id="div1"></div>
  <script>
      var oDiv = document.getElementsByTagName('div')[0];
      var timer = null;
      var alpha = 30;

      oDiv.onmouseover = function () {
          startChange(100);
      }
      oDiv.onmouseout = function () {
          startChange(30);
      }
      function startChange(iTarget) {
          clearInterval(timer);

          timer = setInterval(function () {
              if(alpha<iTarget){
                  speed=1;
              }
              else {
                  speed=-1;
              }
              if(alpha==iTarget){
                  clearInterval(timer);
              }
              else {
                  alpha+=speed;
                  oDiv.style.opacity = alpha/100;
                  oDiv.style.filter = 'alpha(opacity:'+alpha+')';
              }


          },30)



      }


  </script>
</body>
</html>